package pers.zh.parking.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pers.zh.parking.common.Const;
import pers.zh.parking.dao.ParkingLotMapper;
import pers.zh.parking.po.LotQueryBean;
import pers.zh.parking.po.ParkingLot;
import pers.zh.parking.po.ParkingLotExample;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class LotService implements ILotService {

    @Autowired
    ParkingLotMapper lotMapper;

    @Override
    public boolean batchInsert(List<ParkingLot> lots) {
        return lotMapper.batchInsert(lots) > 0;
    }

    @Override
    public List<ParkingLot> getLotsAround(LotQueryBean queryBean) {
        Map<String, Object> map = new HashMap<>();
        map.put("latitude", queryBean.getLatitude());
        map.put("longitude", queryBean.getLongitude());
        if (queryBean.getRadius() == 0) {
            queryBean.setRadius(Const.DEFAULT_DISTANCE);
        }
        map.put("radius", queryBean.getRadius());
        map.put("keyword", queryBean.getKeyword());
        return lotMapper.selectLotsAround(map);
    }

    @Override
    public List<ParkingLot> getAllLots() {
        return lotMapper.selectAll();
    }


}
